package top.toptimus.dto.qcDto;

import lombok.Data;
import lombok.NoArgsConstructor;
import top.toptimus.dto.design.DesignItemCheckDTO;
import top.toptimus.dto.measure.InspectSizeDTO;
import top.toptimus.dto.order.orderSync.orderCommit.OrderCommitDto;

import java.util.ArrayList;
import java.util.List;

/**
 * 质检项目DTO
 *
 * @author gaoyu
 */
@NoArgsConstructor
@Data
public class QcItemsDTO {
    private String batchNo;
    /**
     * 款式信息
     */
    private String styleId;
    private String styleSizeCd;//尺码
    private String styleNameCn;//款式名称
    private String styleImagePath;  //  款式图片路径
    /**
     * 面料信息
     */
    private String styleFabricId;//面料id
    private String materialNameCn;//面料描述名称
    private String materialCode;  //面料号
    private String materialColor;//面料颜色
    private String composition;//面料成分
    private String materialImagePath;   //  面料图片路径
    /**
     * 备注
     */
    private String remarks;
    /**
     * 设计点
     */
    private List<DesignItemCheckDTO> designItemCheckDTOS;
    /**
     * 尺寸
     */
    List<InspectSizeDTO> inspectSizeDTOS;


    public QcItemsDTO(
            OrderCommitDto orderCommitDto,
            String styleImagePath,
            String materialImagePath,
            List<DesignItemCheckDTO> designItemCheckDTOS,
            List<InspectSizeDTO> inspectSizeDTOS
    ) {
        this.styleId = orderCommitDto.getStyleId();
        this.styleSizeCd = orderCommitDto.getStyleSizeCd();
        this.styleNameCn = orderCommitDto.getStyleNameCn();
        this.styleImagePath = styleImagePath;
        this.styleFabricId = orderCommitDto.getStyleFabricId();
        this.materialNameCn = orderCommitDto.getMaterialNameCn();
        this.materialCode = orderCommitDto.getMaterialCode();
        this.materialColor = orderCommitDto.getMaterialColor();
        this.composition = orderCommitDto.getComposition();
        this.materialImagePath = materialImagePath;
        this.designItemCheckDTOS = designItemCheckDTOS;
        this.inspectSizeDTOS = inspectSizeDTOS;
        this.remarks = orderCommitDto.getRemarks();
    }

    public QcItemsDTO buildBatchNo(String batchNo) {
        this.batchNo = batchNo;
        //  清洗质检项目
        List<InspectSizeDTO> inspectSizeDTOS = new ArrayList<>(this.inspectSizeDTOS);
        this.inspectSizeDTOS.clear();
        inspectSizeDTOS.forEach(
                inspectSizeDTO -> {
                    {
                        if (!inspectSizeDTO.getGarmentSize().isNaN() && inspectSizeDTO.getGarmentSize() > 0) {
                            this.inspectSizeDTOS.add(inspectSizeDTO);
                        }
                    }
                }
        );
        return this;
    }
}
